#if 0

#include <iostream>
#include <limits>
#include <string> 
using namespace std;
#include "MenuShow.h"
#include "../ServiceLogic/DataManager.h"


LogManager tmpLogManager;//日志输出

void PermissionTable(Role role)
{
    switch (role)
    {
        case Role::ADMIN:
        {
            std::cout << "==================<管理员权限位>==================\n"
                << "管理员新增用户： 0x0001 << 0,\n"
                << "管理员删除用户： 0x0001 << 1,\n"
                << "管理员修改用户： 0x0001 << 2,\n"
                << "管理员查找用户： 0x0001 << 3,\n"
                << "管理员显示所有用户： 0x0001 << 4,\n"
                << "管理员保存信息： 0x0001 << 5,\n"
                << "管理员查看日志： 0x0001 << 6,\n"
                << "管理员全部权限： 0xFFFF,\n";
            break;
        }
        
        case Role::USER_INFO:
        {
            std::cout << "==================<配件信息管理人员权限位>==================\n"
                << "配件信息人员增加配件： 0x0001 << 0,\n"
                << "配件信息人员删除配件： 0x0001 << 1,\n"
                << "配件信息人员修改配件： 0x0001 << 2,\n"
                << "配件信息人员查找配件： 0x0001 << 3,\n"
                << "配件信息人员显示配件： 0x0001 << 4,\n"
                << "配件信息人员分配未分配位置的配件： 0x0001 << 5,\n"
                << "配件信息人员全部权限： 0xFFFF,\n";
            break;
        }
            
        case Role::USER_STORE_IO:
        {
            std::cout << "==================<仓库信息管理人员权限位>==================\n"
                << "仓库管理人员入库记录添加： 0x0001 << 0, \n"
                << "仓库管理人员入库记录删除： 0x0001 << 1,\n"
                << "仓库管理人员入库记录修改： 0x0001 << 2,\n"
                << "仓库管理人员入库记录查找： 0x0001 << 3,\n"
                << "仓库管理人员入库记录显示： 0x0001 << 4,\n"
                << "仓库管理人员入库记录所有权限： 0x001F,\n"
                << "仓库管理人员出库记录添加： 0x0001 << 5,\n"
                << "仓库管理人员出库记录删除： 0x0001 << 6,\n"
                << "仓库管理人员出库记录修改： 0x0001 << 7,\n"
                << "仓库管理人员出库记录查找： 0x0001 << 8,\n"
                << "仓库管理人员出库记录显示： 0x0001 << 9,\n"
                << "仓库管理人员出库记录所有权限： 0x03E0\n"
                << "仓库管理人员操作入库： 0x0001 << 10,\n"
                << "仓库管理人员操作出库： 0x0001 << 11,\n"
                << "仓库管理人员所有权限： 0xFFFF,\n\n";
            break;
        }
            
        case Role::USER_STORE_CHECK:
        {
            std::cout << "==================<仓库盘点人员权限位>==================\n"
                << "仓库盘点人员盘点权限： 0x0001,\n"
                << "仓库盘点人员显示差异报告： 0x0001 << 1,\n"
                << "仓库盘点人员显示历史差异： 0x0001 << 2,\n"
                << "仓库盘点人员确认差异： 0x0001 << 3,\n"
                << "仓库盘点人员全部权限： 0xFFFF,\n";
            break;
        }
        default:break;      
    }
        
}

/*==========================================<界面菜单基类实现>==========================================*/
/*==============================<主菜单注册界面>==============================*/
void MenuShowBase::menu_main_register()
{
    system("cls");
    std::cout << "|***********注册暂未开放***********|" << endl;
    system("pause");
}

/*==============================<主菜单登录界面界面>==============================*/
void MenuShowBase::menu_main_login()
{
    string name,password;
    BaseManager loginManager;//用来登录
    MenuShow tmpmenu;

    loginManager.load_UserFromFile();

    std::cout << "请输入用户名：";
    std::cin >> name;
    std::cout << "请输入密码：";
    std::cin >> password;

    loginManager.setUser(loginManager.login_verification(name, password));
    if (loginManager.getUser() == nullptr)
    {
        std::cout << "用户名或密码错误！" << endl;
        system("pause");
    }
    else
    {
        std::cout << "登录成功！" << endl;
        std::cout << "你的身份是：";
        switch ((loginManager.getUser())->getRole())
        {
            case Role::ADMIN:
                std::cout << "管理员" << endl;
                system("pause");
                tmpmenu.menu_admin(loginManager.getUser());
                break;
            case Role::USER_INFO:
                std::cout << "配件信息管理人员" << endl;
                system("pause");
                tmpmenu.menu_partInfo(loginManager.getUser());
                break;
            case Role::USER_STORE_CHECK:
                std::cout << "库存盘点人员" << endl;
                system("pause");
                tmpmenu.menu_anomalyStore(loginManager.getUser());
                break;
            case Role::USER_STORE_IO:
                std::cout << "库存管理人员" << endl;
                system("pause");
                tmpmenu.menu_storeManager(loginManager.getUser());
        }
    }
}

/*==============================<授权接口>==============================*/
PB_t MenuShowBase::menu_give_permission(Role role)
{
    PB_t permiss;
    while (1)
    {
        std::cin.clear();
        std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
        std::cout << "请输入权限(格式是以0x开头的4位16进制数)<输入“权限表”以查看权限表>：";std::cin >> std::hex >> permiss;
        if (std::cin.fail())
        {
            PermissionTable(role);
        }
        else
            break;
    }
    std::cin >> std::dec;
    return permiss;
}

/*==========================================<界面菜单类实现>==========================================*/
/*==============================<主界面>==============================*/
void MenuShow::menu_main()
{
    int chose;

    tmpLogManager.load_logFormFile();
    while (1)
    {
        system("cls");

        std::cout << "|****欢迎使用电脑配件库存管理系统****|" << endl;
        std::cout << "|**************1.注册**************|" << endl;
        std::cout << "|**************2.登录**************|" << endl;
        std::cout << "|**************0.退出系统**********|" << endl;
        std::cin >> chose;
        switch (chose)
        {
            case 1:
            {
                MenuShowBase::menu_main_register();
                break;
            }
            case 2:
            {
                MenuShowBase::menu_main_login();
                break;
            }
            case 0:
            {
                std::cout << "退出系统！" << endl;
                exit(0);
            }
            default:
                std::cout << "输入错误！" << endl;
                break;
        }
    }
}

/*==============================<管理员界面>==============================*/
void MenuShow::menu_admin(MYPTR_T& user)
{
    int chose;
    while (1)
    {
        system("cls");
        std::cout << "|****欢迎" << user->getName() << "管理员来到用户信息管理界面！****|" << endl;
        std::cout << "|***************1.管理用户界面***************|" << endl;
        std::cout << "|***************2.日志管理界面***************|" << endl;
        std::cout << "|*****************0.退出账号*****************|" << endl;
        std::cout << "请输入对应的数字进行操作：";std::cin >> chose;
        
        switch (chose)
        {
            case 1:MenuShow::menu_userInfo(user);break;
            case 2:MenuShow::menu_log(user);break;
            case 0:return;
            default:std::cout << "输入错误，请重新输入！" << endl;
        }
    }
    system("pause");
    
}

/*==============================<管理员管理用户子界面>==============================*/
void MenuShow::menu_userInfo(MYPTR_T& user)
{
    UserManager tmpManager;
    int chose;
    User tmpUser;
    MYPTR_T tmpPtr;

    int id,fid;
    string name;
    string password;
    PB_t permissionBits;
    int role;
    string roleDescription;
    
    tmpManager.load_UserFromFile();

    while (1)
    {
        system("cls");
        std::cout << "|****欢迎用户(" << (*user).getName() << ")使用电脑配件库存管理系统****|" << endl;
        std::cout << "|********************1.增********************|" << endl;
        std::cout << "|********************2.删********************|" << endl;
        std::cout << "|********************3.改********************|" << endl;
        std::cout << "|********************4.查********************|" << endl;
        std::cout << "|***************5.显示所有用户***************|" << endl;
        std::cout << "|************6.保存用户信息到文件*************|" << endl;
        std::cout << "|****************0.返回上一级****************|" << endl;
        std::cout << "请输入对应的数字进行操作：";std::cin >> chose;
        if (chose == 0)
            return;
        if ((user->check_permission((UPBits)(PB_t)(0x0001 << (chose - 1)))) != 0)
        {
            std::cout << "您没有该权限，请重新选择操作！" << endl;
            system("pause");
            continue;
        }
        
        switch (chose)
        {
            
            case 1:
            {
                std::cout << "请输入用户id：";
                std::cin >> id;
                std::cout << "请输入用户名：";
                std::cin >> name;
                std::cout << "请输入用户密码：";
                std::cin >> password;
                std::cout << "请分配该用户的角色：(1管理员、2配件信息人员、3仓库出入库管理人员、4仓库盘点人员)";std::cin >> role;
                permissionBits = MenuShowBase::menu_give_permission((Role)role);
                std::cout << "请输入用户描述：";
                std::cin >> roleDescription;
                tmpUser = User(id, name, password, permissionBits, roleDescription);
                tmpManager.add_info(tmpUser, (Role)role);

                /*日志输出*/tmpLogManager.out_log(user->getName(), Role::ADMIN, "添加用户：" + tmpUser.getName() + "\n");
                break;
            }

            case 2:
            {
                tmpManager.show_UserInfo();
                std::cout << "请输入要删除的用户id：";
                std::cin >> id;
                if(tmpManager.delete_info(id)==0)
                    /*日志输出*/tmpLogManager.out_log(user->getName(), Role::ADMIN, "删除用户：" + tmpManager.find_info(id)->getName() + "\n");
                else std::cout << "删除失败！" << endl;
                break;
            }

            case 3:
                tmpManager.show_UserInfo();
                std::cout << "请输入要修改的用户id：";
                std::cin >> fid;
                std::cout << "请输入新的用户id：";
                std::cin >> id;
                std::cout << "请输入新用户名：";
                std::cin >> name;
                std::cout << "请输入用户新密码：";
                std::cin >> password;
                std::cout << "请输入用户新权限：";
                permissionBits = MenuShowBase::menu_give_permission((Role)role);
                std::cout << "请输入用户新描述：";
                std::cin >> roleDescription;
                tmpUser = User(id, name, password, permissionBits, roleDescription);
                tmpManager.modify_info(fid, tmpUser);

                /*日志输出*/tmpLogManager.out_log(user->getName(), Role::ADMIN, "修改用户：" + tmpManager.find_info(fid)->getName() + "为" + tmpUser.getName()+"\n");
                break;
            case 4:
                std::cout << "请输入要查找的用户id：";
                std::cin >> id;
                if ((tmpPtr = tmpManager.find_info(id)) == nullptr)
                {
                    std::cout << "用户不存在！" << endl;
                }
                else
                {
                    std::cout << tmpPtr->serialize();
                }

                /*日志输出*/tmpLogManager.out_log(user->getName(), Role::ADMIN, "查找用户：" + tmpPtr->getName()+"\n");
                break;
            case 5:
                tmpManager.show_UserInfo();
                    
                break;
            case 6:
                tmpManager.save_UserToFile();

                /*日志输出*/tmpLogManager.out_log(user->getName(), Role::ADMIN, "保存用户信息到文件\n");
                break;
            case 0:
            {
                return;
            }
            default:std::cout << "输入错误！请重新输入" << endl;
        }
        system("pause");
    }
}

/*==============================<管理人员查看日志子界面>==============================*/
void MenuShow::menu_log(MYPTR_T& user)
{
    int chose;

    int fidLogId;

    myTime_t operationTimeStart[2], operationTimeEnd[2];
    string operatorName;
    // Role role;
    int roleInt;

    while (1)
    {
        system("cls");
        std::cout << "|***********欢迎" << user->getName() << "来到日志管理界面***********|" << endl;
        std::cout << "|********************1.显示所有日志********************|" << endl;
        std::cout << "|********************2.查找日志编号********************|" << endl;
        std::cout << "|********************3.按照时间范围显示日志********************|" << endl;
        std::cout << "|********************4.按照用户名显示日志********************|" << endl;
        std::cout << "|********************5.按照角色显示日志********************|" << endl;
        std::cout << "|********************0.返回上一级********************|" << endl;
        std::cout << "请输入对应的数字进行操作：";std::cin >> chose;
        
        if (user->check_permission(UPBits::USER_ADMIN_LOG))
        {
            std::cout << "您没有该权限，请重新选择操作！" << endl;
            system("pause");
            continue;
        }

        switch (chose)
        {
            case 1:
            {
                tmpLogManager.show_log();
                break;
            }
            case 2:
            {
                cout << "请输入日志编号：";cin >> fidLogId;
                tmpLogManager.find_log(fidLogId);
                break;
            }
            case 3:
            {
                cout << "请输入起始时间：(请按照年-月-日 时:分:秒格式输入)";cin >> operationTimeStart[1] >> operationTimeStart[2];
                cout << "请输入结束时间：(请按照年-月-日 时:分:秒格式输入)";cin >> operationTimeEnd[1] >> operationTimeEnd[2];
                tmpLogManager.find_log(operationTimeStart[1] + " " + operationTimeStart[2], operationTimeEnd[1] + " " + operationTimeEnd[2]);
                break;
            }
            case 4:
            {
                cout << "请输入操作人员姓名：";cin >> operatorName;
                tmpLogManager.find_log(operatorName);
                break;
            }
            case 5:
            {
                cout << "请输入操作角色：(1管理员、2配件信息人员、3仓库出入库管理人员、4仓库盘点人员)";cin >> roleInt;
                tmpLogManager.find_log(Role(roleInt));
                break;
            }
            case 0:return;
            default:std::cout << "操作无效！请重新输入" << endl;
        }
        system("pause");
    }
}


/*==============================<配件信息管理界面>==============================*/
void MenuShow::menu_partInfo(MYPTR_T& user)
{
    Part tmpPart;
    PartManager tmpManager;

    shared_ptr<Part> tmpPtr;
    
    int id, newId, fid, assigningId;
    std::string name;     
    std::string model;    
    double price;         
    std::string location, assigningLocation;
    int stockQuantity;    
    int stockUpperLimit;  
    int stockLowerLimit;  

    int chose;

    tmpManager.load_PartFromFile();

    while (1)
    {
        system("cls");
        std::cout << "|***欢迎" << user->getName() << "来到配件信息管理界面***|" << endl;
        std::cout << "|***************1.增***************|" << endl;
        std::cout << "|***************2.删***************|" << endl;
        std::cout << "|***************3.改***************|" << endl;
        std::cout << "|***************4.查***************|" << endl;
        std::cout << "|**********5.显示所有配件**********|" << endl;
        std::cout << "|*******6.分配未入库配件信息*******|" << endl;
        std::cout << "|**************0.退出**************|" << endl;
        std::cin >> chose;

        if (chose == 0)
            return;
        if ((user->check_permission((UPBits)(PB_t)(0x0001 << (chose - 1)))) != 0)
        {
            std::cout << "您没有该权限，请重新选择操作！" << endl;
            system("pause");
            continue;
        }

        switch (chose)
        {
            case 1:
            {
                std::cout << "请输入配件id：";std::cin >> id;
                std::cout << "请输入配件名称：";std::cin >> name;
                std::cout << "请输入配件型号：";std::cin >> model; 
                std::cout << "请输入配件价格：";std::cin >> price;
                std::cout << "请输入配件位置：";std::cin >> location;
                std::cout << "请输入配件库存数量：";std::cin >> stockQuantity;
                std::cout << "请输入配件库存上限：";std::cin >> stockUpperLimit;
                std::cout << "请输入配件库存下限：";std::cin >> stockLowerLimit;
                tmpPart = Part(id, name, model, price, location, stockQuantity, stockUpperLimit, stockLowerLimit);
                if (tmpManager.add_info(tmpPart) != 0)
                    std::cout << "添加失败" << endl;
                else
                {
                    std::cout << "添加成功" << endl;
                    /*日志输出*/tmpLogManager.out_log(user->getName(), user->getRole(), "添加配件：" + tmpPart.serialize());
                }
                    
                tmpManager.save_PartToFile();
                break;
            }

            case 2:
            {
                tmpManager.show_PartInfo();
                std::cout << "请输入要删除的配件id：";std::cin >> id;
                if (tmpManager.delete_info(id) != 0)
                    std::cout << "删除失败" << endl;
                else
                {
                    /*日志输出*/tmpLogManager.out_log(user->getName(), user->getRole(), "删除配件：" + to_string(id));
                    std::cout << "删除成功" << endl;
                }
                tmpManager.save_PartToFile(); 
                break;
            }
            case 3:
            {
                tmpManager.show_PartInfo();
                std::cout << "请输入要修改的配件id：";cin >> id;
                cout << "请输入新的配件id：";cin >> newId;
                cout << "请输入新的配件名称：";cin >> name;
                cout << "请输入新的配件型号：";cin >> model; 
                cout << "请输入新的配件价格：";cin >> price;
                cout << "请输入新的配件位置：";cin >> location;
                cout << "请输入新的配件库存数量：";cin >> stockQuantity;
                cout << "请输入新的配件库存上限：";cin >> stockUpperLimit;
                cout << "请输入新的配件库存下限：";cin >> stockLowerLimit;
                tmpPart = Part(newId, name, model, price, location, stockQuantity, stockUpperLimit, stockLowerLimit);
                if (tmpManager.modify_info(id, tmpPart) != 0)
                    cout << "修改失败" << endl;
                else
                {
                    /*日志输出*/tmpLogManager.out_log(user->getName(), user->getRole(), "修改配件：" + tmpPart.serialize());
                    cout << "修改成功" << endl;
                }
                    
                tmpManager.save_PartToFile();
                break;
            }
            case 4:
            {
                cout << "请输入要查找的配件Id：";cin >> fid;
                if ((tmpManager.find_info_all(fid)) <= 0)
                    cout << "Id为" << fid << "的配件信息不存在！" << endl;
                else
                    cout << tmpPtr->serialize();
                break;
            }

            case 5:
            {
                if (tmpManager.show_PartInfo() != 0)
                    cout << "当前并无配件信息，请先添加" << endl;
                break;
            }

            case 6:
            {
                int assigningCount = 0;
                if (tmpManager.show_not_in_store_info() <= 0)
                    break;
                cout << "请问你要分配多少个配件：";cin >> assigningCount;

                for (int i = 0;i < assigningCount;i++)
                {
                    cout << "（如果有多个相同配件ID，请按照显示顺序分配）" << endl;
                    cout << "请输入配件ID进行分配位置：";cin >> assigningId;
                    cout << "请输入要分配的位置：";cin >> assigningLocation;
                    tmpManager.assigning_partLocation(assigningId, assigningLocation);
                    tmpManager.save_PartToFile();

                    /*日志输出*/tmpLogManager.out_log(user->getName(), user->getRole(), "分配未入库配件位置：" + to_string(assigningId) + " " + assigningLocation + "\n");
                }
                
                break;
            }

            case 0:
            {
                cout << "退出账号！" << endl;
                return;
            }

            default:
            {
                cout << "请输入正确的选项！" << endl;
            }
        }
        system("pause");
    }
    
}

/*==============================<仓库管理人员界面>==============================*/
void MenuShow::menu_storeManager(MYPTR_T& user)
{
    int chose;

    while (1)
    {
        system("cls");
        cout << "|****欢迎" << user->getName() << "来到仓库管理界面！****|" << endl;
        cout << "|***************1.仓库入库记录界面***************|" << endl;
        cout << "|***************2.仓库出库记录界面***************|" << endl;
        cout << "|***************3.仓库操作界面***************|" << endl;
        cout << "|*****************0.退出账号*****************|" << endl;
        cout << "请输入对应的数字进行操作：";cin >> chose;

        switch (chose)
        {
            case 1: MenuShow::menu_inStore(user);break;
            case 2: MenuShow::menu_outStore(user);break;
            case 3: MenuShow::menu_operationStore(user);break;
            case 0:return;
            default:cout << "输入错误！请重新输入！" << endl;system("pause");
        }

    }
    
}

/*==============================<仓库管理人员入库记录子界面>==============================*/
void MenuShow::menu_inStore(MYPTR_T& user)
{
    StoreInManager tmpStoreInManager;
    StoreInRecord tmpStoreInRecord;

    int chose;

    int recordId;
    int recordPartId;
    string timeString[2];
    string description;
    int inQuantity;

    while (1)
    {
        tmpStoreInManager.load_StoreFromFile();
        system("cls");
        cout << "|***********欢迎" << user->getName() << "来到仓库入库信息管理界面！***********|" << endl;
        cout << "|***************1.增***************|" << endl;
        cout << "|***************2.删***************|" << endl;
        cout << "|***************3.改***************|" << endl;
        cout << "|***************4.查***************|" << endl;
        cout << "|*********5.显示所有入库记录**********|" << endl;
        cout << "|**************0.退出**************|" << endl;
        cout << "请输入对应的数字进行操作：";cin >> chose;

        if (chose == 0)
            return;
        if ((user->check_permission((UPBits)(PB_t)(0x0001 << (chose - 1)))) != 0)
        {
            std::cout << "您没有该权限，请重新选择操作！" << endl;
            system("pause");
            continue;
        }

        switch (chose)
        {
            case 1:
            {
                cout << "请输入要记录的配件id：";cin >> recordPartId;
                cout << "请输入该记录的时间：(请按照年-月-日 时:分:秒格式输入)";cin >> timeString[0] >> timeString[1];
                cout << "请输入该记录的描述：";cin >> description;
                cout << "请输入该记录的入库数量：";cin >> inQuantity;
                tmpStoreInRecord = StoreInRecord(tmpStoreInManager.get_record_endId() + 1, recordPartId, timeString[0] + ' ' + timeString[1], description, inQuantity);
                tmpStoreInManager.add_info(tmpStoreInRecord);
                if (tmpStoreInManager.save_StoreToFile())
                    cout << "添加失败" << endl;
                else
                {
                    /*日志输出*/tmpLogManager.out_log(user->getName(), user->getRole(), "添加入库记录：" + to_string(recordPartId) + " " + timeString[0] + ' ' + timeString[1] + " " + description + " " + to_string(inQuantity));
                    cout << "添加成功" << endl;
                }
                    
                break;
            }
            case 2:
            {
                tmpStoreInManager.show_StoreInfo();
                cout << "请输入要删除的记录id：";cin >> recordId;
                if (tmpStoreInManager.delete_info(recordId) || tmpStoreInManager.save_StoreToFile())
                    cout << "删除失败" << endl;
                else
                {
                    /*日志输出*/tmpLogManager.out_log(user->getName(), user->getRole(), "删除入库记录：" + to_string(recordId));
                    cout << "删除成功" << endl;
                }
                    
                break;
            }
            case 3:
            {
                tmpStoreInManager.show_StoreInfo();
                cout << "请输入要修改的记录编号id：";cin >> recordId;
                cout << "请输入此纪录新的配件id：";cin >> recordPartId;
                cout << "请输入此纪录新的时间：(请按照年-月-日 时:分:秒格式输入)";cin >> timeString[0] >> timeString[1];
                cout << "请输入此纪录新的描述：";cin >> description;
                cout << "请输入此纪录新的入库数量：";cin >> inQuantity;
                tmpStoreInRecord = StoreInRecord(recordId, recordPartId, timeString[0] + ' ' + timeString[1], description, inQuantity);
                if (tmpStoreInManager.modify_info(recordId, tmpStoreInRecord) || tmpStoreInManager.save_StoreToFile())
                    cout << "修改失败" << endl;
                else
                {
                    /*日志输出*/tmpLogManager.out_log(user->getName(), user->getRole(), "修改入库记录：" + to_string(recordId) + " " + to_string(recordPartId) + " " + timeString[0] + ' ' + timeString[1] + " " + description + " " + to_string(inQuantity));
                    cout << "修改成功" << endl;
                }
                    
                break;
            }
            case 4:
            {
                tmpStoreInManager.show_StoreInfo();
                cout << "请输入要查找的记录id：";cin >> recordId;
                if (tmpStoreInManager.find_info(recordId) == nullptr)
                    cout << "查无此记录" << endl;
                else
                    cout << tmpStoreInManager.find_info(recordId)->serialize() ;
                break;
            }
            case 5:
            {
                tmpStoreInManager.show_StoreInfo();
                break;
            }
            case 0:return;
                
            default:cout << "操作无效，请重新输入！" << endl;
        }
        system("pause");
    }

}

/*==============================<仓库管理人员出库记录子界面>==============================*/
void MenuShow::menu_outStore(MYPTR_T& user)
{
    StoreOutManager tmpStoreOutManager;
    StoreOutRecord tmpStoreOutRecord;

    int chose;

    int recordId;
    int recordPartId;
    string timeString[2];
    string description;
    int outQuantity;

    while (1)
    {
        tmpStoreOutManager.load_StoreFromFile();
        system("cls");
        cout << "|***********欢迎" << user->getName() << "来到仓库出库信息管理界面！***********|" << endl;
        cout << "|***************1.增***************|" << endl;
        cout << "|***************2.删***************|" << endl;
        cout << "|***************3.改***************|" << endl;
        cout << "|***************4.查***************|" << endl;
        cout << "|*********5.显示所有出库记录**********|" << endl;
        cout << "|**************0.退出**************|" << endl;
        cout << "请输入对应的数字进行操作：";cin >> chose;

        if (chose == 0)
            return;
        if ((user->check_permission((UPBits)(PB_t)(0x0001 << (chose +5 - 1)))) != 0)
        {
            std::cout << "您没有该权限，请重新选择操作！" << endl;
            system("pause");
            continue;
        }
        
        switch (chose)
        {
            case 1:
            {
                cout << "请输入要记录的配件id：";cin >> recordPartId;
                cout << "请输入该记录的时间：(请按照年-月-日 时:分:秒格式输入)";cin >> timeString[0] >> timeString[1];
                cout << "请输入该记录的描述：";cin >> description;
                cout << "请输入该记录的出库数量：";cin >> outQuantity;
                tmpStoreOutRecord = StoreOutRecord(tmpStoreOutManager.get_record_endId() + 1, recordPartId, timeString[0] + ' ' + timeString[1], description, outQuantity);
                tmpStoreOutManager.add_info(tmpStoreOutRecord);
                if (tmpStoreOutManager.save_StoreToFile())
                    cout << "添加失败" << endl;
                else
                {
                    tmpLogManager.out_log(user->getName(), user->getRole(), "添加出库记录：" + to_string(tmpStoreOutRecord.getrecordId()) + " " + to_string(recordPartId) + " " + timeString[0] + ' ' + timeString[1] + " " + description + " " + to_string(outQuantity));
                    cout << "添加成功" << endl;
                }
                    
                break;
            }
            case 2:
            {
                tmpStoreOutManager.show_StoreInfo();
                cout << "请输入要删除的记录id：";cin >> recordId;
                if (tmpStoreOutManager.delete_info(recordId) || tmpStoreOutManager.save_StoreToFile())
                    cout << "删除失败" << endl;
                else
                {
                    tmpLogManager.out_log(user->getName(), user->getRole(), "删除出库记录：" + to_string(recordId));
                    cout << "删除成功" << endl;
                }
                    
                break;
            }
            case 3:
            {
                tmpStoreOutManager.show_StoreInfo();
                cout << "请输入要修改的记录编号id：";cin >> recordId;
                cout << "请输入此纪录新的配件id：";cin >> recordPartId;
                cout << "请输入此纪录新的时间：(请按照年-月-日 时:分:秒格式输入)";cin >> timeString[0] >> timeString[1];
                cout << "请输入此纪录新的描述：";cin >> description;
                cout << "请输入此纪录新的出库数量：";cin >> outQuantity;
                tmpStoreOutRecord = StoreOutRecord(recordId, recordPartId, timeString[0] + ' ' + timeString[1], description, outQuantity);
                if (tmpStoreOutManager.modify_info(recordId, tmpStoreOutRecord) || tmpStoreOutManager.save_StoreToFile())
                    cout << "修改失败" << endl;
                else
                {
                    tmpLogManager.out_log(user->getName(), user->getRole(), "修改出库记录：" + to_string(recordId) + " " + to_string(recordPartId) + " " + timeString[0] + ' ' + timeString[1] + " " + description + " " + to_string(outQuantity));
                    cout << "修改成功" << endl;
                }
                    
                break;
            }
            case 4:
            {
                tmpStoreOutManager.show_StoreInfo();
                cout << "请输入要查找的记录id：";cin >> recordId;
                if (tmpStoreOutManager.find_info(recordId) == nullptr)
                    cout << "查无此记录" << endl;
                else
                    cout << tmpStoreOutManager.find_info(recordId)->serialize() ;
                break;
            }
            case 5:
            {
                tmpStoreOutManager.show_StoreInfo();
                break;
            }
            case 0:return;
                
            default:cout << "操作无效，请重新输入！" << endl;
        }
        system("pause");
    }

    
}
/*==============================<仓库管理人员操作子界面>==============================*/
void MenuShow::menu_operationStore(MYPTR_T& user)
{
    StoreBaseManager tmpManager;
    int chose;

    int findPartId;
    string findLocation;
    int quantity;
    int realQuantityIO;


    while (1)
    {
        system("cls");
        cout << "|****欢迎" << user->getName() << "来到仓库操作界面！****|" << endl;
        cout << "|*****1.仓库入库操作*****|" << endl;
        cout << "|*****2.仓库出库操作*****|" << endl;
        cout << "|*****0.返回上一级*****|" << endl;
        cout << "请输入对应的数字进行操作：";cin >> chose;

        if (chose == 0)
            return;
        if ((user->check_permission((UPBits)(PB_t)(0x0001 << (chose +10 - 1)))) != 0)
        {
            std::cout << "您没有该权限，请重新选择操作！" << endl;
            system("pause");
            continue;
        }

        switch (chose)
        {
            case 1:
            {
                tmpManager.load_PartFromFile();
                tmpManager.show_PartInfo();

                cout << "请输入要入库的配件ID：";cin >> findPartId;
                cout << "请输入该配件的位置：";cin >> findLocation;

                if (tmpManager.PartManager::find_info(findPartId,findLocation) == nullptr)
                {
                    cout << findLocation << "没有ID为" << findPartId << "的配件" << endl;
                    break;
                }

                cout << "请输入你要入库的配件数量：";cin >> quantity;
                if ((realQuantityIO = tmpManager.store_in(tmpManager.getPartLib(), findPartId, findLocation, quantity)) < 0)
                    cout << "入库失败" << endl;
                else
                {
                    tmpLogManager.out_log(user->getName(), user->getRole(), "入库：" + to_string(findPartId) + " " + findLocation + " " + to_string(quantity));
                    cout << "已成功入库" << realQuantityIO << endl;
                }
                    if (realQuantityIO != quantity)
                    cout << "剩余" << quantity - realQuantityIO << "个配件待配件信息人员分配位置" << endl;
                tmpManager.save_PartToFile();
                break;
            }

            case 2:
            {
                tmpManager.load_PartFromFile();
                tmpManager.show_PartInfo();

                cout << "请输入要出库的配件id：";cin >> findPartId;
                cout << "请输入该配件的位置：";cin >> findLocation;

                if (tmpManager.PartManager::find_info(findPartId) == nullptr)
                {
                    cout << findLocation << "没有ID为" << findPartId << "的配件" << endl;
                    break;
                }

                cout << "请输入你要出库的配件数量：";cin >> quantity;
                realQuantityIO = tmpManager.store_out(tmpManager.getPartLib(), findPartId, findLocation, quantity);
                if (realQuantityIO == -1)
                {
                    cout << "出库失败" << endl;
                    break;
                }
                else
                {
                    tmpLogManager.out_log(user->getName(), user->getRole(), "出库：" + to_string(findPartId) + " " + findLocation + " " + to_string(quantity));
                    cout << realQuantityIO << "个配件出库成功" << endl;
                    tmpManager.save_PartToFile();
                }
                break;
            }

            case 0:return;
            
            default:
                cout << "请输入正确的选项" << endl;
                break;
        }
        system("pause");
    }
}


/*==============================<仓库盘点人员界面>==============================*/
//盘点差异需要根据配件ID，和位置，来查找到对应的配件
void MenuShow::menu_anomalyStore(MYPTR_T& user)
{
    StoreAnomalyManager tmpStoreAnomalyManager;
    PartManager tmpPartManager;

    vector<shared_ptr<StoreCompare>> comareLib;
    StoreCompare tmpStoreCompare;

    int chose;
    int checkCount;

    int partId;
    int anomalyId;
    string location;
    int realQuantity;

    vector<int> confirmIdLib;
    
    while (1)
    {
        tmpPartManager.load_PartFromFile();
        tmpStoreAnomalyManager.load_AllStoreAnomalyFromFile();
        tmpStoreAnomalyManager.load_CurrentStoreAnomalyFromFile();

        system("cls");
        cout << "|****欢迎" << user->getName() << "来到仓库盘点界面！****|" << endl;
        cout << "|***************1.开始盘点***************|" << endl;
        cout << "|***************2.查看差异***************|" << endl;
        cout << "|***************3.查看历史差异***************|" << endl;
        cout << "|***************4.确认差异***************|" << endl;
        cout << "|***************0.返回上一级***************|" << endl;
        cout << "请输入你需要执行的操作：";cin >> chose;

        if (chose == 0)
            return;
        if ((user->check_permission((UPBits)(PB_t)(0x0001 << (chose - 1)))) != 0)
        {
            std::cout << "您没有该权限，请重新选择操作！" << endl;
            system("pause");
            continue;
        }

        switch (chose)
        {
            case 1:
            {
                cout << "请输入你要盘点配件的个数：";cin >> checkCount;
                comareLib.clear();
                for (int i = 0;i < checkCount;i++)
                {
                    cout << "请输入第" << i + 1 << "个配件的id：";cin >> partId;
                    cout << "请输入第" << i + 1 << "个配件的库存位置：";cin >> location;
                    cout << "请输入第" << i + 1 << "个配件的库存数量：";cin >> realQuantity;
                    tmpStoreCompare = StoreCompare(partId, location, realQuantity);
                    comareLib.push_back(make_shared<StoreCompare>(tmpStoreCompare));
                }

                tmpStoreAnomalyManager.compare_to_lib(tmpPartManager.getPartLib(), comareLib, checkCount);
                tmpStoreAnomalyManager.save_CurrentStoreAnomalyToFile();
                tmpStoreAnomalyManager.save_AllStoreAnomalyToFile();
                tmpLogManager.out_log(user->getName(), user->getRole(), "盘点了" + to_string(checkCount) + "个配件");
                break;
            }
            case 2:
            {
                tmpStoreAnomalyManager.show_CurrentStoreAnomaly();
                break;
            }
            case 3:
            {
                tmpStoreAnomalyManager.show_AllStoreAnomaly();
                break;
            }
            case 4:
            {
                tmpStoreAnomalyManager.show_CurrentStoreAnomaly();
                cout << "请选择你要确认的方式（1.自定义确认数量 2.全部确认）";cin >> chose;
                if (chose == 1)
                {
                    confirmIdLib.clear();
                    cout << "请输入确认数量";cin >> checkCount;
                    for (int i = 0;i < checkCount;i++)
                    {
                        cout << "请输入第" << i + 1 << "个异常ID";cin >> anomalyId;
                        confirmIdLib.push_back(anomalyId);
                    }
                    tmpStoreAnomalyManager.confirm_differences(tmpPartManager.getPartLib(), checkCount, confirmIdLib);

                    tmpLogManager.out_log(user->getName(), user->getRole(), "确认了" + to_string(checkCount) + "个异常");
                }
                else if (chose == 2)
                {
                    tmpStoreAnomalyManager.confirm_differences(tmpPartManager.getPartLib());

                    tmpLogManager.out_log(user->getName(), user->getRole(), "确认了所有异常");
                }
                else { cout << "输入错误" << endl; }
                tmpPartManager.save_PartToFile();
                tmpStoreAnomalyManager.save_AllStoreAnomalyToFile();
                tmpStoreAnomalyManager.save_CurrentStoreAnomalyToFile();
                break;
            }
            case 0:return;
            default:cout << "操作无效，请重新输入" << endl;
                break;
        }
        system("pause");
    }
}

#endif
